package ru.ipccenter.jshell.frontend.shell;

import java.io.File;
import java.io.IOException;


public class Executor {
    
    public static InterprocessStreamInternal exec(InterprocessStreamInternal inStream,
                        ShellInternal shell, String[] args, String[] env, File directory) {

        Process executable;
        try {
            executable = Runtime.getRuntime().exec(args, env, directory);
        } catch (IOException e) {
            throw new RuntimeException("Can't execute (" + args + ")", e);
        }
        
        inStream.setOutput(executable.getOutputStream());
        InterprocessStreamInternal outStream = 
            new InterprocessStreamInternalImpl(executable.getInputStream(), shell);
        inStream.start();
        
        return outStream;
    }
}
